package com.itheima.mapper;

import com.itheima.domain.Classes;
import com.itheima.domain.Student;
import org.apache.ibatis.annotations.One;
import org.apache.ibatis.annotations.Result;
import org.apache.ibatis.annotations.Results;
import org.apache.ibatis.annotations.Select;

import java.util.List;

public interface StudentMapper {
    @Select("select * from student")
    @Results({
            // 封装了学生基本信息
            @Result(column = "sid", property = "sid",id = true),
            @Result(column = "name", property = "name"),
            @Result(column = "age", property = "age"),

            // 学生所属班级信息     private Classes classes
            @Result(
                    property = "classes",
                    javaType = Classes.class,
                    column = "cid",        // 根据学生表cid字段的值，去查询班级表
                    one = @One(select = "com.itheima.mapper.ClassesMapper.findById")    // 根据学生cid字段的值,调用ClassesMapper接口findById去查询
            )
    })
    public List<Student> findAllStudent();
}
